package com.blog.config;

import com.blog.common.Constant;
import com.blog.seckill.goods.Good;
import com.blog.service.ChatService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.InMemoryChatMemory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Description;

import java.util.function.Function;

/**
 * @ClassName chatConfig
 * @Destription 对话配置-对话记忆
 * @Author 天堂小野花
 * @Date 2025/8/17  20:57
 * @Version 1.0
 */
@Configuration
public class chatConfig {
    @Autowired
     ChatService chatService;

    @Bean
    public ChatMemory chatMemory(){
        //todo 这里将对话信息保存到了内存中，如果需要持久化保存到redis，需要重写方法。
        return new InMemoryChatMemory();
    }

    public Good good;
    public record createGoodRequest(Integer goodId, Integer goodNum,Integer userId){}
    public record getGoodRequest(Integer goodId, Integer goodNum){}
    @Bean
    @Description("处理购买商品下订单")
    public Function<createGoodRequest,String> createOrder(){

        return createGoodRequest -> {
          //apply 调用方法
            String goodOrder = chatService.createGoodOrder(createGoodRequest.goodId(), createGoodRequest.goodNum(),createGoodRequest.userId());

           return goodOrder;
        };
    }
    @Bean
    @Description("获取商品信息")
    public Function<getGoodRequest,Good> getGood(){
        return getGoodRequest -> {
            //apply 调用方法
            System.out.println(getGoodRequest.goodId());
            Good res = chatService.chatSelectGood(getGoodRequest.goodId());
            return res;
        };
    }
}
